Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR has added a function
knn_threaded
. I am able to achieve several X speedup from multithreading, but a several X slowdown for small problems. This is an acceptable tradeoff IMO, and possibly some smart heuristic can be implemented to only multithread when beneficial.An internal
_batch_inds
function accomplishes the batching for separating the task into as few partitions as possible, based on the following quote from the readme:"It is generally better for performance to query once with a large number of points than to query multiple times with one point per query."
I have been using the following function for timing:
which on my computer
with 4 physical and 8 logical cores, gives the following results:
This PR probably requires some cleaning, especially in determining a good API and possibly heuristics for when to use multithreading. I do not think that there should be a separate knn_threaded function, but I implemented it like this for now for easy comparison. If it is confirmed to be overall faster, then I think it should be the default option.
PS - this is my first attempt at multithreading, so please doublecheck things thoroughly before merging anything.